﻿/*
 * @Autor: PK
 * @Date: 2022/01/14 20:31:SS
 * @Description: 用来做性能测试的一套路网
 */

using System;
using System.Collections.Generic;
using ShkSimulation.core.dao.input.loader;
using ShkSimulation.core.dao.input.resource;
using ShkSimulation.core.factory;
using ShkSimulation.core.template;
using ShkSimulation.core.template.agency;
using ShkSimulation.core.template.customer;
using ShkSimulation.core.template.model;

namespace ShkSimulation.carsharing.efficiency {

	public class EvaluationNetwork: AbstractNetwork {

        private static int uniqueIndex = 1;
        public static int stationCount = 2;
        public static int roadCount = 1;
        public static double stationServiceRate = 6;
        public static double roadServiceRate = 2;
        public static double DayArriveCount = 1200;

        private EvaluationNetwork(int id,
            NetworkInputData inputData, 
            NetworkResultCollector resultCollector, 
            DemandManager demandManager, 
            int seed) : base(id, inputData, resultCollector, demandManager, FactoriesCreateFunction, seed) {
            
            EvaluationDemandManager.DayArriveCount = DayArriveCount;
            
        }

        public static EvaluationNetwork BuildNetwork() {
            NetworkEnvironment inputData = new NetworkEnvironment(InputConfig.Empty(), new EmptyResourceLoader());
            return new EvaluationNetwork(-1, inputData, new NetworkResultHolder(), new EvaluationDemandManager(), 1);
        }
        
        protected static List<AgencyFactory> FactoriesCreateFunction(NetworkInputData networkInput) {
            AgencyFactory station = DefaultStationFactory(networkInput);
            AgencyFactory road = DefaultRoadFactory(networkInput);
            return new List<AgencyFactory>() {
                station, road
            };
        }

        protected static AgencyFactory DefaultStationFactory(NetworkInputData networkInput) {
            return FactoryProvider.CreateFactory("station", CreateDemoStations);
            
            Dictionary<int, Agency> CreateDemoStations(Resource resource, List<CreateParam> createParams) {
                Dictionary<int, Agency> result = new Dictionary<int, Agency>();
                for (int i = 0; i < stationCount; i++) {
                    BaseAgencyParams agencyParams = BaseAgencyParams.Create(uniqueIndex++);
                    EvaluationStation station = new EvaluationStation(agencyParams);
                    station.ServiceRateHelper = new StableServiceRateHelper(TimeSpan.FromHours(1 / stationServiceRate));
                    result.Add(agencyParams.UniqueId, station);
                }
                return result;
            }
        }

        protected static AgencyFactory DefaultRoadFactory(NetworkInputData networkInput) {
            return FactoryProvider.CreateFactory("road", CreateDemoRoads);
            Dictionary<int, Agency> CreateDemoRoads(Resource resource, List<CreateParam> createParams) {
                Dictionary<int, Agency> result = new Dictionary<int, Agency>();
                BaseAgencyParams agencyParams = BaseAgencyParams.Create(uniqueIndex++);
                EvaluationRoad road = new EvaluationRoad(agencyParams);
                road.LastStation = 1;
                road.NextStation = 2;
                road.ServiceRateHelper = new StableServiceRateHelper(TimeSpan.FromHours(1 / roadServiceRate));
                result.Add(agencyParams.UniqueId, road);
                return result;
            }
        }

    }

}